﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HST.Domain.Seedwork
{
    public class AggregateRoot<TKey> : IAggregateRoot<TKey>
        where TKey : IEquatable<TKey>
    {
        public virtual TKey ID { get; set; }

        #region 重载方法

        /// <summary>
        /// 重载Equals方法
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is AggregateRoot<TKey>))
            {
                return false;
            }

            if (Object.ReferenceEquals(this, obj))
            {
                return true;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// 重载操作符 ==
        /// </summary>
        /// <param name="left">左值</param>
        /// <param name="right">右值</param>
        /// <returns></returns>
        public static bool operator ==(AggregateRoot<TKey> left, AggregateRoot<TKey> right)
        {
            if (Object.Equals(left, null))
            {
                return (Object.Equals(right, null)) ? true : false;
            }
            else
            {
                return left.Equals(right);
            }
        }

        /// <summary>
        /// 重载操作符 !=
        /// </summary>
        /// <param name="left">左值</param>
        /// <param name="right">右值</param>
        /// <returns></returns>
        public static bool operator !=(AggregateRoot<TKey> left, AggregateRoot<TKey> right)
        {
            return !(left == right);
        }

        #endregion

    }
}
